/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* middleNode(ListNode* head) 
    {
        if(head == NULL)
            return NULL;
        
        if(head != NULL && head -> next == NULL)
            return head;

        ListNode* faster = head;
        ListNode* slower = head;

        while(faster != NULL && faster -> next != NULL)
        {
            faster = faster -> next -> next;
            slower = slower -> next;
        }
        
        return slower;
        
    }
};